package com.hyt.it.ogt.kq.service.gov.api.cj;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.common.apiInfor.DataType;
import com.hyt.common.apiInfor.ParamType;
import com.hyt.it.ogt.kq.service.gov.api.cj.model.TaskCandidateAreaVO;
import com.hyt.it.ogt.kq.common.gov.constant.ResponseCode;
import com.hyt.it.ogt.kq.common.config.exception.KqException;
import com.hyt.it.ogt.kq.service.gov.service.ITaskCandidateAreaService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 成绩服务调用接口
 * </p>
 *
 * @author huangyh
 * @since 2022-01-18
 */
@RestController
@Api(tags = "29.成绩服务调用接口", value = "成绩服务调用接口")
@ApiSort(value = 29)
@RequestMapping("/api/cj")
@Slf4j
public class CjApi {

    @Resource
    private ITaskCandidateAreaService iTaskCandidateAreaService;

    @ApiOperation(
            value = "29.1 获取任务下的考生省份信息",
            notes = "20000:成功; 43290101:获取任务下的考生省份信息异常"
    )
    @ApiOperationSort(value = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "taskId",
                    value = "考试任务id",
                    dataType = DataType.STRING,
                    paramType = ParamType.QUERY,
                    required = true
            )
    })
    @GetMapping("/get/getCandidateProvinceByTaskId")
    public ApiResponse<List<TaskCandidateAreaVO>> getCandidateProvinceByTaskId(@RequestParam String taskId) {
        log.info("# 获取任务下的考生省份信息参数: {}", taskId);
        try {
            List<TaskCandidateAreaVO> taskCandidateAreaVOList =
                    iTaskCandidateAreaService.getProvinceByTaskId(taskId);
            return ApiResponse.<List<TaskCandidateAreaVO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(taskCandidateAreaVOList)
                    .build();
        } catch (KqException k) {
            log.error("# 获取任务下的考生省份信息业务异常: {}", k.getErrMsg());
            return ApiResponse.<List<TaskCandidateAreaVO>>builder()
                    .code(k.getErrCode())
                    .build();
        } catch (Exception e) {
            log.error("# 获取任务下的考生省份信息异常:", e);
            return ApiResponse.<List<TaskCandidateAreaVO>>builder()
                    .code(ResponseCode.GET_PROVINCE_BY_TASK_ID_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "29.2 获取任务下指定省份下的市信息",
            notes = "20000:成功; 43290201:获取任务下指定省份下的市信息异常"
    )
    @ApiOperationSort(value = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "taskId",
                    value = "考试任务id",
                    dataType = DataType.STRING,
                    paramType = ParamType.QUERY,
                    required = true
            ),
            @ApiImplicitParam(
                    name = "province",
                    value = "省份编号",
                    dataType = DataType.STRING,
                    paramType = ParamType.QUERY,
                    required = true
            )
    })
    @GetMapping("/get/getCandidateCityById")
    public ApiResponse<List<TaskCandidateAreaVO>> getCandidateCityById(@RequestParam String taskId,
                                                                       @RequestParam String province) {
        log.info("# 获取任务下指定省份下的市信息参数: {}, {}", taskId, province);
        try {
            List<TaskCandidateAreaVO> taskCandidateAreaVOList =
                    iTaskCandidateAreaService.getCityById(taskId, province);
            return ApiResponse.<List<TaskCandidateAreaVO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(taskCandidateAreaVOList)
                    .build();
        } catch (KqException k) {
            log.error("# 获取任务下指定省份下的市信息业务异常: {}", k.getErrMsg());
            return ApiResponse.<List<TaskCandidateAreaVO>>builder()
                    .code(k.getErrCode())
                    .build();
        } catch (Exception e) {
            log.error("# 获取任务下指定省份下的市信息异常:", e);
            return ApiResponse.<List<TaskCandidateAreaVO>>builder()
                    .code(ResponseCode.GET_CANDIDATE_CITY_BY_ID_EXCEPTION.getCode())
                    .build();
        }
    }

}
